package com.service.luo;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dao.luo.WordDao;
import com.dao.luo.WordselDao;
import com.entity.Word;
import com.entity.Wordsel;

@Service
public class WordService {
	@Autowired
	private WordDao wordDao;
	@Autowired
	private WordselDao wordselDao;
	
	public List<Word> findAllWord(){
		List<Word> words = (List<Word>)wordDao.findAll();
		for(Word word : words) {
			List<Wordsel> wsels = word.getWordsels();
			wsels.size();
			for(Wordsel wordsel : wsels) {
				wordsel = wordselDao.findOne(wordsel.getSelvalno());
			}
			word.setWordsels(wsels);
		}
		return words;
	}
	
	public List<Word> findByOrderByWordnoAsc(){
		return wordDao.findByOrderByWordnoAsc();
	}
	
	/*
	 * public List<Word> findAllWordByAsc(){ List<Object[]> objs =
	 * wordDao.getWordByAsc(); List<Word> words = new ArrayList<Word>();
	 * for(Object[] obj : objs) { Wordsel wordsel= (Wordsel)obj[1]; Word word =
	 * (Word)obj[0]; word.addWordsel(wordsel); } return words; }
	 */
	 
	
	public Word findOneWordByNo(Long wordno) {
		Word word = wordDao.findOne(wordno);
		List<Wordsel> wsels = word.getWordsels();
		wsels.size();
		for(Wordsel wordsel:wsels) {
			wordsel = wordselDao.findOne(wordsel.getSelvalno());
		}
		word.setWordsels(wsels);
		return word;
	}
	
	public List<Word> findWordsByWtno(Long wtno){
		return wordDao.findWordsByWtno(wtno);
	}
}
